package ink.metoo.gude

import ink.metoo.gude.module.security.domain.AuthVerificationCodeConst
import ink.metoo.gude.module.security.service.VerificationCodeService
import ink.metoo.gude.util.logger
import jakarta.transaction.Transactional
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import java.util.concurrent.TimeUnit
import kotlin.test.assertEquals

@Suppress("LocalVariableName")
@SpringBootTest
class GudeServerApplicationTests {

    private val log = logger()

    @Autowired
    private lateinit var verificationCodeService: VerificationCodeService

    @Test
    fun contextLoads() {
    }

    @Test
    @Transactional
    fun testVerificationCode() {
        val key = "example@example.org"
        val code_1 =
            verificationCodeService.restVerificationCode(key, AuthVerificationCodeConst.REGISTER_TYPE)
        TimeUnit.SECONDS.sleep(10)
        val code_2 =
            verificationCodeService.getVerificationCode(key, AuthVerificationCodeConst.REGISTER_TYPE)
        log.info("code_1: $code_1, code_2: $code_2")
        assertEquals(code_1, code_2)
    }


}
